import re

re_tags = re.compile("<([a-z_]+)>(.*?)</\\1>", re.I+re.U+re.S+re.M)

def xml2dict(sXML):
    "Regular expression based xml2dict"
    D = {}
    matches = re_tags.findall(sXML)
    
    for match in matches:
        k = match[0]
        
        if len(re_tags.findall(match[1]))<1:
            D[k] = match[1]
        else:
            D[k] = xml2dict(match[1])
        
    
    return D

if '__main__' == __name__:
    s = """
    <cmdinfo>
    <message> ji kuch behtari to hui hay, ap apni sunain, tabiyat kaisi hay ab?</message><cmd>SENDSMS</cmd><contact>03333713260</contact></cmdinfo>
    """
    
    print repr(xml2dict(s))